/*    */ package blockbuster.components.lifetime;
/*    */ 
/*    */ import blockbuster.components.BedrockComponentBase;
/*    */ import blockbuster.emitter.BedrockEmitter;
/*    */ import blockbuster.math.molang.MolangException;
/*    */ import blockbuster.math.molang.MolangParser;
/*    */ import blockbuster.math.molang.expressions.MolangExpression;
/*    */ import com.google.gson.JsonElement;
/*    */ import com.google.gson.JsonObject;
/*    */ 
/*    */ public class BedrockComponentLifetimeLooping
/*    */   extends BedrockComponentLifetime {
/* 13 */   public MolangExpression sleepTime = MolangParser.ZERO;
/*    */ 
/*    */   
/*    */   public BedrockComponentBase fromJson(JsonElement elem, MolangParser parser) throws MolangException {
/* 17 */     if (!elem.isJsonObject())
/*    */     {
/* 19 */       return super.fromJson(elem, parser);
/*    */     }
/*    */     
/* 22 */     JsonObject element = elem.getAsJsonObject();
/*    */     
/* 24 */     if (element.has("sleep_time"))
/*    */     {
/* 26 */       this.sleepTime = parser.parseJson(element.get("sleep_time"));
/*    */     }
/*    */     
/* 29 */     return super.fromJson((JsonElement)element, parser);
/*    */   }
/*    */ 
/*    */ 
/*    */   
/*    */   public JsonElement toJson() {
/* 35 */     JsonObject object = (JsonObject)super.toJson();
/*    */     
/* 37 */     if (!MolangExpression.isZero(this.sleepTime))
/*    */     {
/* 39 */       object.add("sleep_time", this.sleepTime.toJson());
/*    */     }
/*    */     
/* 42 */     return (JsonElement)object;
/*    */   }
/*    */ 
/*    */ 
/*    */   
/*    */   public void update(BedrockEmitter emitter) {
/* 48 */     double active = this.activeTime.get();
/* 49 */     double sleep = this.sleepTime.get();
/* 50 */     double age = emitter.getAge();
/*    */     
/* 52 */     emitter.lifetime = (int)(active * 20.0D);
/*    */     
/* 54 */     if (age >= active && emitter.playing)
/*    */     {
/* 56 */       emitter.stop();
/*    */     }
/*    */     
/* 59 */     if (age >= sleep && !emitter.playing)
/*    */     {
/* 61 */       emitter.start();
/*    */     }
/*    */   }
/*    */ }


/* Location:              D:\fanbian\[D][龙之核心]DragonCore-2.6.0.3.jar!\blockbuster\components\lifetime\BedrockComponentLifetimeLooping.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */